<%--                                                                       --%>
<%-- Copyright (c) 2003 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ page import =  "java.util.*, java.net.*,
                    com.broadvision.web.util.ViewDynaBean,
                    org.apache.struts.validator.DynaValidatorForm,
                    org.apache.commons.beanutils.PropertyUtils"
%>

<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html-el" %>


<SCRIPT language="javascript">

  function doRoleNewAction(theForm) {
      theForm.action = '<html:rewrite page="/cm/contentRoleNew.do"/>';
      theForm.submit();
      return true;
  }

  function gotoFirstPage(formName) {
    if (doValidateEntriesPerPage(formName) == false) {
      return false;
    }
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      thisForm.currentPageNumber.value = 1;
      thisForm.submit();
    }
  }
  
  function gotoPreviousPage(formName) {
    if (doValidateEntriesPerPage(formName) == false) {
      return false;
    }
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      var currentPageNumber = thisForm.currentPageNumber.value;
      currentPageNumber--;
      if (thisForm.entriesPerPage.value != <bean:write name="cmContentRoleListForm" property="entriesPerPage"/>) {
        currentPageNumber = 1;
      }
      if (currentPageNumber > 0) {
        thisForm.currentPageNumber.value = currentPageNumber;
        thisForm.submit();
      }
    }
  }
  
  function gotoNextPage(formName) {
    if (doValidateEntriesPerPage(formName) == false) {
      return false;
    }
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      var currentPageNumber = thisForm.currentPageNumber.value;
      currentPageNumber++;
      if (thisForm.entriesPerPage.value != <bean:write name="cmContentRoleListForm" property="entriesPerPage"/>) {
        currentPageNumber = 1;
      }
      if (currentPageNumber <= thisForm.totalPageNumber.value) {
        thisForm.currentPageNumber.value = currentPageNumber;
        thisForm.submit();
      }
    }
  }
  
  function gotoLastPage(formName) {
    if (doValidateEntriesPerPage(formName) == false) {
      return false;
    }
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      if (thisForm.entriesPerPage.value != <bean:write name="cmContentRoleListForm" property="entriesPerPage"/>) {
        thisForm.currentPageNumber.value = 1;
      }
      else {
        thisForm.currentPageNumber.value = thisForm.totalPageNumber.value;
      }
      thisForm.submit();
    }
  }

  function doGo(formName) {
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      if (thisForm.entriesPerPage.value != <bean:write name="cmContentRoleListForm" property="entriesPerPage"/>) {
        thisForm.currentPageNumber.value = 1;
        thisForm.submit();
        return true;
      }
    }
    return false;
  }
  
  function checkNumberOnly(e) {
    var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
      return false;
    }
    else {
      return true;
    }
  }

  function doValidateEntriesPerPage(formName) {
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      if (thisForm.entriesPerPage == null) {
        return true;
      }
      var entriesPerPageString = thisForm.entriesPerPage.value;
      var len = entriesPerPageString.length;
      var i = 0;
      for (i = 0; i < len; i++) {
        if (entriesPerPageString.charAt(i) < '0' || entriesPerPageString.charAt(i) > '9') {
          alert("<bean:message bundle='cm.messages' key="cm.common.pagination.validation.itemsPerPage"/>");
          thisForm.entriesPerPage.select();
          thisForm.entriesPerPage.focus();
          return false;
        }
      }
      if (thisForm.entriesPerPage.value < 1 || thisForm.entriesPerPage.value > 2147483647) {
        alert("<bean:message bundle='cm.messages' key="cm.common.pagination.validation.itemsPerPage"/>");
        thisForm.entriesPerPage.select();
        thisForm.entriesPerPage.focus();
        return false;
      }
      else {
        return true;
      }
    }
    return false;
  }

</SCRIPT>
  
<html:form action="/cm/contentRoleList.do" onsubmit="return doGo('cmContentRoleListForm');">
<html:hidden name="cmContentRoleListForm" property="currentPageNumber"/>
<html:hidden name="cmContentRoleListForm" property="totalPageNumber"/>
<html:hidden name="cmContentRoleListForm" property="lastPage"/>
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr> 
    <td valign="top" width="100%">
      <div class="pageTitle"><bean:message bundle='cm.messages' key="cm.content.role.header.rolelist"/></div>
      <div class="errorMessage"><html:errors bundle='cm.messages' /></div>
      <%
        ViewDynaBean roleListView = (ViewDynaBean) request.getAttribute("cmContentRoleListView");
        Integer roleListLength = (Integer) PropertyUtils.getSimpleProperty(roleListView, "numOfRoles");
      %>
      <div class="pageSubtitle">
        <span class="left"><bean:message bundle='cm.messages' key="cm.content.role.result" arg0="<%= roleListLength.toString() %>" />
        </span>
        <span class="right">
            <html:button styleClass="titleButton" property="submitBtn" onclick="return doRoleNewAction(document.cmContentRoleListForm);">
              <bean:message bundle='cm.messages' key="button.newRole"/>
            </html:button>

        </span>
      </div> 
      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Content Services role list" width="100%">
        <tr class="listHeader">
          <th valign="top" id="roleName" align="left">
            <bean:message bundle='cm.messages' key="cm.content.role"/>
          </th>
          <th valign="top" id="friendlyName" align="left">
            <bean:message bundle='cm.messages' key="cm.content.role.friendlyName"/>
          </th>
          <th valign="top" id="desc"  align="left">
            <bean:message bundle='cm.messages' key="header.description"/>
          </th>
          <th valign="top" id="actions" align="left" nowrap>
            <bean:message bundle='cm.messages' key="header.actions"/>
          </th>
        </tr>
        <logic:empty name="cmContentRoleListView" property="instances">
          <tr class="listEven">
            <td align="center" colspan="5">
              <bean:message bundle='cm.messages' key="cm.content.role.noRoleList"/>
            </td>
          </tr>
        </logic:empty>
        <logic:notEmpty name="cmContentRoleListView" property="instances">
          <logic:iterate id="instance" name="cmContentRoleListView" property="instances" indexId="i">
            <tr class="<%=i.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">
              <td valign="top"  headers="roleName">
                <html:link page="/cm/contentRoleView.do" paramId="oid" paramName="instance" paramProperty="oid">
                  <!--bean:write name="instance" property="name"/-->
                  <bean:define id="roleName" name="instance" property="name"/>
                  <% String  temp = (String )pageContext.getAttribute("roleName");
                          if(temp != null && temp.equalsIgnoreCase("ProductManager"))
                          {
                  %>
                             <bean:message bundle='cm.messages' key="cm.content.role.ProductManager"/>
                  <%      }
                          else if(temp != null && temp.equalsIgnoreCase("MarketingManager"))
                          {
                  %>
                             <bean:message bundle='cm.messages' key="cm.content.role.MarketingManager"/>
                  <%
                          }
                          else if(temp != null && temp.equalsIgnoreCase("Owner"))
							{
				  %>
						    <bean:message bundle='cm.messages' key="cm.content.role.Owner"/>
					<%	}
                        else{
                  %>
                             <%=temp%>
                  <%
                          }
                  %>
                </html:link>
              </td>
              <td valign="top" headers="friendlyName">
                  <bean:write name="instance" property="friendlyName"/> 
              </td>
              <td valign="top" headers="desc">
                <bean:write name="instance" property="desc"/>
              </td>
              <td valign="top" nowrap align="left" headers="actions">
                <a href='<%=response.encodeURL(request.getContextPath() + "/cm/contentRoleEdit.do?oid=")%><bean:write name="instance" property="oid"/>' >
                <img src="<%=request.getContextPath()%>/mc/images/action/icon_edit.gif" width="15" height="15" border="0"  class="actionIcon" alt="<bean:message bundle='cm.messages' key="image.alt.edit"/>" /></a>
              </td>
            </tr>
          </logic:iterate>
        </logic:notEmpty>
      </table>
      <logic:notEmpty name="cmContentRoleListView" property="instances">
        <div class="pagination">
          <bean:message bundle='cm.messages' key="cm.common.pagination.show"/>

          <bean-el:message key="cm.common.pagination.show" bundle="cm.messages"/>
          <html-el:select property="entriesPerPage" size="1" onchange="doGo('cmContentRoleListForm')">
            <html-el:option value="10">10</html-el:option>
            <html-el:option value="20">20</html-el:option>
            <html-el:option value="30">30</html-el:option>
            <html-el:option value="50">50</html-el:option>
            <html-el:option value="100">100</html-el:option>
          </html-el:select>

          <bean:message bundle='cm.messages' key="cm.common.pagination.itemsPerPage"/>
          &nbsp;
          <logic:greaterThan name="cmContentRoleListForm" property="totalPageNumber" value="1">
            &nbsp;&nbsp;&nbsp;
            <logic:greaterThan name="cmContentRoleListForm" property="currentPageNumber" value="0">
              <logic:greaterThan name="cmContentRoleListForm" property="totalPageNumber" value="1">
                <logic:greaterThan name="cmContentRoleListForm" property="currentPageNumber" value="1">
                  <a href="#" class="paginationBtn" onclick="javascript:gotoFirstPage('cmContentRoleListForm')">
                    <bean:message bundle='cm.messages' key="cm.common.pagination.first"/></a>
                  <a href="#" class="paginationBtn" onclick="javascript:gotoPreviousPage('cmContentRoleListForm')">
                    <bean:message bundle='cm.messages' key="cm.common.pagination.previous"/></a>
                </logic:greaterThan>
              </logic:greaterThan>
              <bean:define id="currentPageNumberAttr" name="cmContentRoleListForm" property="currentPageNumber"/>
              <bean:define id="totalPageNumberAttr" name="cmContentRoleListForm" property="totalPageNumber"/>
              <% Integer currentPageNumberInt = (Integer)pageContext.getAttribute("currentPageNumberAttr"); %>
              <% Integer totalPageNumberInt = (Integer)pageContext.getAttribute("totalPageNumberAttr"); %>
              <bean:message bundle='cm.messages' key="cm.common.pagination.pageOf" 
                arg0="<%= currentPageNumberInt.toString() %>" 
                arg1="<%= totalPageNumberInt.toString() %>"/>
              <logic:greaterThan name="cmContentRoleListForm" property="totalPageNumber" value="1">
                <logic:equal name="cmContentRoleListForm" property="lastPage" value="false">
                  <a href="#" class="paginationBtn" onclick="javascript:gotoNextPage('cmContentRoleListForm')">
                    <bean:message bundle='cm.messages' key="cm.common.pagination.next"/></a>
                  <a href="#" class="paginationBtn" onclick="javascript:gotoLastPage('cmContentRoleListForm')">
                    <bean:message bundle='cm.messages' key="cm.common.pagination.last"/></a>
                </logic:equal>
              </logic:greaterThan>
            </logic:greaterThan>
          </logic:greaterThan>
        </div>
      </logic:notEmpty>
    </td>
  </tr>
</table>
</html:form>

